{% extends "skia_telemetry_base.html" %}

{% block content %}

<center>
{% if info_msg %}<font color="red"><b>{{ info_msg }}</b></font><br/><br/>{% endif %}

<h2>Run Chromium patches on the top 10k webpages</h2>
<br/>

{{ pending_tasks_count }} tasks currently in the <a align="center" href='pending_tasks'>Queue</a>
<br/>
Documentation for Chromium Tryserver and benchmarks is <a href='https://docs.google.com/a/chromium.org/document/d/1GhqosQcwsy6F-eBAmFn_ITDF7_Iv_rY9FhCKwAnk9qQ/edit#'>here</a>
<br/></br>
<a href="javascript:toggleDetails();">Show/hide algorithm details</a>
<script type="text/javascript">
  function toggleDetails() {
    var details = ["benchmark_details", "variance_details", "outliers_details", "repeated_runs"];
    for (var i=0; i<details.length; i++) {
      if (document.getElementById(details[i]).style.display == 'none') {
        document.getElementById(details[i]).style.display = '';
      } else {
        document.getElementById(details[i]).style.display = 'none';
      }
    }
  }
</script>
<br/>
<br/>

{% if not is_google_chromium_user %}
  Must have a google or chromium account to trigger benchmarks (contact rmistry@)<br/><br/>
{% else %}
  <form name="ChromiumTryForm" action="chromium_try" method="post">
  <table cellingpadding="5">
    <tr>                                                                      
      <td>Benchmark to run</td>
      <td>
        <select id="benchmark_name" name="benchmark_name" onchange="populateThreshold(this)"> 
          {% for benchmark in supported_benchmarks %}                             
            <option value="{{ benchmark }}">{{ benchmark }}</option>
          {% endfor %}                                                        
        </select>
        Uses the telemetry revision from this <a href='https://skia.googlesource.com/buildbot/+/master/DEPS'>DEPS</a> file.
      </td>
    </tr>                                                                     
    <tr id="benchmark_details" style="display:none">                                                                      
      <td>Benchmark Arguments</td>                                            
      <td>
        <input type="text" size="35" name="benchmark_arguments" value="--output-format=csv"/>
        The Benchmark must output in CSV to do meaningful comparisions.
      </td>
    </tr>
    <tr id="repeated_runs" style="display:none">
      <td>Repeat Pageset Runs</td>
      <td>
        <select id="num_repeated_runs" name="num_repeated_runs">
          <option value="1">1</option>
          <option value="3" selected>3</option>
          <option value="5">5</option>
        </select>
        Repeats each pageset and takes smallest values. More documentation is <a href='https://docs.google.com/a/chromium.org/document/d/1GhqosQcwsy6F-eBAmFn_ITDF7_Iv_rY9FhCKwAnk9qQ/edit#heading=h.rlyfe3y13j6m'>here</a>.
      </td>
    </tr>
    <tr id="variance_details" style="display:none">
      <td>Variance Threshold</td>                                               
      <td>                                                                      
        <input type="text" name="variance_threshold" size"5" value="5"/>
        <a id="variance_threshold_info"></a>
      </td>                                                                     
    </tr>                                                                       
    <tr id="outliers_details" style="display:none">
      <td>Discard Outliers</td>                                               
      <td>                                                                      
        <input type="text" name="discard_outliers" size"5" value="0"/>
      </td>                                                                     
    </tr>
    <tr>
      <td>Pagesets Type</td>
      <td>
        <select id="pageset_type" name="pageset_type">
          {% for pageset in pagesets %}
            <option value="{{ pageset }}">{{ pageset }}</option>
          {% endfor %}
        </select>
      </td>
    </tr>                                                                       
    <tr>                                                                        
      <td>Description</td>                                             
      <td><input type="text" name="description" size="35"></td>                 
    </tr>
    <tr>
      <td>Chromium Git patch (optional)<br/>Applied to Chromium ToT</td>
      <td>
        <textarea name="chromium_patch" cols="80" rows="15"></textarea>
      </td>
    </tr>
    <tr>
      <td>Blink Git patch (optional)<br/>Applied to Blink Rev in <a href='http://src.chromium.org/viewvc/chrome/trunk/src/DEPS'>DEPs</a></td>
      <td>
        <textarea name="blink_patch" cols="80" rows="15"></textarea>
      </td>
    </tr>
    <tr>
      <td>Skia Git patch (optional)<br/>Applied to Skia Rev in <a href='http://src.chromium.org/viewvc/chrome/trunk/src/DEPS'>DEPs</a></td>
      <td>
        <textarea name="skia_patch" cols="80" rows="15"></textarea>
      </td>
    </tr>
    <tr>                                                                      
      <td colspan="2" align="center"><input type="submit" value="Queue Chromium Try Task"></td>
    </tr>
  </table>

  <br/>
  <br/>

  </form>
  <script>
    function populateThreshold(sel) {
      var form = sel.form,
          value = sel.options[sel.selectedIndex].value;
      switch(value) {
        case 'rasterize_and_record_micro':
          form.variance_threshold.value = '0';
          break;
        case 'pixeldiffs':
          form.variance_threshold.value = '0';
          break;
        case 'smoothness':
          form.variance_threshold.value = '0';
          break;
        default:
          form.variance_threshold.value = '0';
      }

      // Update the variance threshold information message.
      info_msg = '% is the recommended variance threshold to use for '
      document.getElementById('variance_threshold_info').innerHTML = (
          form.variance_threshold.value + info_msg + value);
    }

    populateThreshold(document.getElementById('benchmark_name'));
  </script>
{% endif %}
<hr/>

  <h2>Your Try runs history</h2>
  <br/>

  {% if chromium_try_tasks %}
  <table border="1" cellpadding="5">
    <tr bgcolor="#CCCCFF">
      <td><b>Description</b></td>
      <td><b>Benchmark Name</b></td>
      <td><b>Benchmark Arguments</b></td>
      <td><b>Repeat Runs</b></td>
      <td><b>Variance Threshold</b></td>
      <td><b>Discard Outliers</b></td>
      <td><b>Pagesets Type</b></td>
      <td><b>Requested Time</b></td>
      <td><b>Completed Time</b></td>
      <td><b>Chromium Patch Link</b></td>
      <td><b>Blink Patch Link</b></td>
      <td><b>Skia Patch Link</b></td>
      <td><b>Build Log</b></td>
      <td><b>Telemetry nopatch Log</b></td>
      <td><b>Telemetry withpatch Log</b></td>
      <td><b>HTML comparision</b></td>
      <td><b>Delete</b></td>
    </tr>
    {% for task in chromium_try_tasks %}
    <tr {% if not task.completed_time %}bgcolor="#8FDF5F"{% endif %} >
      <td>{{ task.description }}</td>
      <td>{{ task.benchmark_name }}</td>
      <td>{{ task.benchmark_arguments }}</td>
      <td>
        {% if task.num_repeated_runs %}
          {{ task.num_repeated_runs }}
        {% else %}
          1
        {% endif %}
      </td>
      <td>{{ task.variance_threshold }}</td>
      <td>{{ task.discard_outliers }}</td>
      <td>
        {% if task.pageset_type %}
          {{ task.pageset_type }}
        {% else %}
          10k
        {% endif %}
      </td>
      <td>{{ task.requested_time }}</td>
      <td>
        {% if task.completed_time %}
          {{ task.completed_time }}
        {% else %}
          {% include "col_status.html" %}
        {% endif %}
      </td>
      <td align="center">
        {% if task.chromium_patch_link %}
          <a href='{{ task.chromium_patch_link }}' target='_blank'>patch</a>
        {% else %}
          {% include "col_status.html" %}
        {% endif %}
      </td>
      <td align="center">
        {% if task.blink_patch_link %}
          <a href='{{ task.blink_patch_link }}' target='_blank'>patch</a>
        {% else %}
          {% include "col_status.html" %}
        {% endif %}
      </td>
      <td align="center">
        {% if task.skia_patch_link %}
          <a href='{{ task.skia_patch_link }}' target='_blank'>patch</a>
        {% else %}
          {% include "col_status.html" %}
        {% endif %}
      </td>
      <td align="center">
        {% if task.build_log_link %}
          <a href='{{ task.build_log_link }}' target='_blank'>build_log</a>
        {% else %}
          {% include "col_status.html" %}
        {% endif %}
      </td>
      <td align="center">
        {% if task.telemetry_nopatch_log_link %}
          <a href='{{ task.telemetry_nopatch_log_link }}' target='_blank'>nopatch_log</a>
        {% else %}
          {% include "col_status.html" %}
        {% endif %}
      </td>
      <td align="center">                                                       
        {% if task.telemetry_withpatch_log_link %}                                
          <a href='{{ task.telemetry_withpatch_log_link }}' target='_blank'>withpatch_log</a>
        {% else %}
          {% include "col_status.html" %}
        {% endif %}                                                             
      </td>
      <td align="center">                                                       
        {% if task.html_output_link %}                                
          <a href='{{ task.html_output_link }}' target='_blank'>output</a>
        {% else %}
          {% include "col_status.html" %}
        {% endif %}                                                             
      </td>
      <td align="center">
        <form action="chromium_try" name="delete_chromium_try_task" method="post">
          <input type='hidden' name='delete' value='{{ task.key.id_or_name }}'>
          <input type='submit' value='Delete' {% ifequal task.key.id_or_name oldest_pending_task_key %}disabled{% endifequal %}>
        </form>
      </td>
    </tr>
    {% endfor %}
  </table>
  {% else %}
    No Previous runs yet.
  {% endif %}
  <br/>
  <a href='all_tasks#chromium_try'>View runs of all users</a>
</center>

{% endblock %}
